<?php

namespace App\HttpController\Api;

use App\Component\User;
use App\HttpController\Api\BaseController;
use App\Logic\Account\CashoutService;
use App\Model\Account\CashoutModel;

/**
 * Cashout 提现
 */
class Cashout extends BaseController {
    /**列表*/
    public function index()
    {
        $service = new CashoutService();
        $result = $service->getLists($this->request());
        return $this->writeJsonByOutput($result);
    }
    /**字典*/
    public function dict()
    {
        $service = new CashoutService();
        $result = $service->getDict($this->request());
        return $this->writeJsonByOutput($result);
    }
    /**本金账户提现*/
    public function create()
    {
        $service = new CashoutService();
        $data = $this->getJson();
        if($data['account_type'] == CashoutModel::ACCOUNT_TYPE_FUNDS){
            $result = $service->create($data);
        }elseif ($data['account_type'] == CashoutModel::ACCOUNT_TYPE_PROFIT){
            $result = $service->profit($data);
        }else{
            throw new \Exception('account_type参数错误');
        }
        return $this->writeJsonByOutput($result);
    }
    /**测试*/
    public function tst()
    {
        $service = new CashoutService();
        $data    = $this->getJson();
        $result = $service->getPrincipalAccountMaxCashoutAmount($data['user_id']);
        return $this->writeJson(200, $result);
    }
    /**收益账户提现*/
    public function profit()
    {
        $service = new CashoutService();
        $data = $this->getJson();
        $result = $service->profit($data);
        return $this->writeJsonByOutput($result);
    }

}
